﻿using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    // 自定义属性渲染器
    [CustomPropertyDrawer(typeof(MyAttribute))]
    public class MyAttributeDrawer : PropertyDrawer 
    {
        // 绘制
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GUI.Label(new Rect(position.position, new Vector2(position.width, 20)), $"这个使用了 My Attribute：{property.intValue}");
            EditorGUI.PropertyField(new Rect(position.x, position.y + 20, position.width, position.height - 20),
                property, label);
        }
        
        // 计算绘制位置
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return base.GetPropertyHeight(property, label) + 20;
        }
    }
}